#############################################################################
# Copyright (c) 2009 Dmitry Grushin <dgrushin@gmail.com>.
#
# This file is part of clupower (cluster power manager utility)
#
# Clupower is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Clupower is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Clupower.  If not, see <http://www.gnu.org/licenses/>.
#
# Contributors:
#    Dmitry Grushin <dgrushin@gmail.com> - initial API and implementation
#############################################################################

$:.unshift File.join(File.dirname(__FILE__),'..','lib')

require 'server'
require 'client'
require 'cpmonitor'

class TestServer < Test::Unit::TestCase

  def setup
    $settings_path = File.dirname(__FILE__)
    $settings_file = "settings.test3.yaml"

    Settings.instance.load

    File.delete(Utils.get_lock_file) if File.exist?(Utils.get_lock_file)
  end

  def test_serv1
    File.delete("test_touch_file") if File.exist?("test_touch_file")
    serv = CPServer.new
    serv.nodes_on("node")
    assert(File.exist?("test_touch_file"))
  end

  def test_serv2
    File.delete("test_touch_file") if File.exist?("test_touch_file")
    serv = CPServer.new
    serv.nodes_sleep("node")
    assert(File.exist?("test_touch_file"))
  end

  def test_serv3
    assert_raise CPI1 do
      Settings.instance.set_algo("AAA")
    end
    Settings.instance.set_algo("MIN_WIDTH")
  end

  def test_serv4
    CPMonitor.instance.log_message("--------- TEST SERVER ------------- ")

    serv = CPServer.new
    client = CPClient.new

    st = Thread.new do
      serv.run
    end
    sleep 10
    client.shutdown
    st.join
  end
end
